<!DOCTYPE html>
<html ng-app="app">
<head>
    <meta charset="utf-8">
    <title>验证手机号</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="__STATIC__/index/css/mui.min.css">
    <link rel="stylesheet" href="__STATIC__/index/css/commen.css" />
    <link rel="stylesheet" href="__STATIC__/index/css/my/account/register.css" />
</head>
<script src="__STATIC__/index/js/mui.min.js"></script>
<script src="__STATIC__/index/js/jquery.min.js"></script>
<script src="__STATIC__/index/js/angular.min.js"></script>
<script src="__STATIC__/index/js/my/account/register.js"></script>
<script src="__STATIC__/layer/layer.js"></script>
<script type="text/javascript">
    function getCode() {
        var reg = /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;
        var phone = $("#phone_input").val();
        var flag = reg.test(phone);
        if (flag) {
              $.post("{:url('user/sendCode')}", { phone: phone },
                 function (data) {
                     /*alert(data.code);*/
                     /* alert(data);*/
                     //假设返回的json数据里有status及info2个属性
                     //有时候可以直接ajaxobj.status或者ajaxobj["status"]去访问
                     //但有时候，却要通过eval()或者 $.parsejson();才可以通过ajaxobj.status访问，而且这种情况下，需要是complete而不是success
                      /*ajaxobj=eval("("+data+")");
                      alert(ajaxobj.code);*/
                      if (data.code == 1) {
                            layer.msg(data.msg, { time: 1000 }, function (){
                                send_timer();
                            })
                      }else {
                            layer.msg(data.msg);
                      }
                });
        } else {
            layer.msg('请输入有效的手机号码!');
        }
    }
    function send_timer() {
        $('.send_code').text("59s后重试").attr('disabled', 'disabled');
        var code_second = 58;
        var timerHandler;
        timerHandler = setInterval(function () {
            if (code_second <= 0) {
                window.clearInterval(timerHandler); //当执行的时间59s,结束时，取消定时器
                code_second = 58;
                $('.send_code').text('发送验证码').removeAttr('disabled');
            } else {
                $('.send_code').text(code_second + "s后重试").attr('disabled', 'disabled');
                code_second--;
            }
        }, 1000)
    }
    function cclick() {
             var phone = $("#phone_input").val();
             var code = $("#code").val();
             $.post("{:url('user/check_phone')}", { code: code, phone: phone},
                function (data) {
                    if (data.code == 1) {
                            loading(1);
                    }else if(data.code == 2){
                            loading(2);
                    }else {
                        layer.msg(data.msg);
                    }
                });
    }
    function loading(type) {
        mui('#pop_into').popover('show');
        var home_second = 3;
        var homeTimer = setInterval(function () {
            home_second--;
            $('.go_home').text("即将跳转首页（" + home_second + "s）");
            if (home_second <= 0) {
                window.clearInterval(homeTimer);
                //执行跳转操作
                if(type==1){
                    location.href = "{:url('user/Officialsetpass')}";
                }else{
                    location.href = "{:url('user/Unofficialsetpass')}";
                }
            }
        }, 1000)
    }
</script>
<body ng-controller="register_controller">
<header class="mui-bar mui-bar-nav">
    <a class="mui-icon mui-icon-left-nav mui-pull-left" onclick="javascript :history.back(-1);"></a>
</header>
<div id="pullrefresh" class="mui-content">
    <div class="account_container">
        <h4 class="mui-text-center">验证手机号</h4>
        <div class="mui-clearfix phone_box form_line">
            <input type="text" class="input_case" id="phone_input" name="phone_input" placeholder="请输入手机号" />
            <button class="send_code" onclick="getCode()">发送验证码</button>
        </div>
        <div class="mui-clearfix form_line">
            <input type="text" id="code" class="input_case" name="pass_code" placeholder="请输入验证码" />
        </div>
       <!-- <div class="mui-clearfix form_line phone_box">
            <p class="pop_msg">未注册手机验证后自动登录</p>
            <input type="password" id="password" class="input_case" name="pass_word" placeholder="请设置登录密码" />
        </div>-->
        <button class="register_btn" onclick="cclick()">下一步</button>
        <!--<div class="mui-clearfix checkbox_line mui-text-center">
            <label for="agree_agreement" id="agreement_label">
                <input type="checkbox" value="1" checked="checked" name="xieyi" id="agree_agreement" /> 我已阅读并同意“用户协协议和隐私条款”
                <div class="show-box" /> </div>
        </label>-->
    </div>
   <!-- <div class="mui-clearfix checkbox_line mui-text-center">
        <a href="" class="go_login or_text" ng-click="goPage('index.html')">账号密码登录</a>
    </div>-->
</div>
</div>
<div id="pop_into" class="mui-popover mui-popover-action mui-popover-bottom">
    <div class="pop_container">
        <img src="__STATIC__/index/img/my/register.png" alt="" class="gift_box" />
        <h4>恭喜您，验证成功</h4>
        <p class="go_home">即将跳转首页（3s）</p>
        <button class="pop_btn" ng-click="goPage('{:url('/index/recharge/real_name')}')">马上设置密码</button>
    </div>
    <div class="close_container" ng-click="close_pop()">
        <i class="mui-icon mui-icon-close"></i>
    </div>
</div>
</body>

</html>